import { dataType } from "element-plus/es/components/table-v2/src/common";
import instacne from "../request";
import type { Ref } from "vue";
import { id } from "element-plus/es/locale";

interface IFlashListParams {
  keyword?: string | Ref<string> | number;
  pageNum?: number | Ref<number>;
  pageSize?: number | Ref<number>;
  parentId?: number | Ref<number>;
}

interface IFlashListItem {
  id: number;
  title: string;
  startDate: string;
  endDate: string;
  status: number;
  createTime: string;
}

interface IFlashListRes {
  pageNum: number;
  pageSize: number;
  totalPage: number;
  total: number;
  list: IFlashListItem[];
}

/* 
    获取活动列表
    /flash/list
*/
const getFlashList = (data?: IFlashListParams): Promise<IFlashListRes> => {
  return instacne.get("/flash/list", {
    params: data,
  });
};
/*
    秒杀时间段列表
    /flashSession/list
*/

interface IFlashSessionListItem {
  createTime: string;
  endTime: string;
  id: number;
  name: string;
  startTime: string;
  status: number;
}

const getFlashSessionList = (): Promise<IFlashSessionListItem> => {
  return instacne.get("/flashSession/list");
};

/* 
    编辑时间段列表
    /flashSession/update
*/
const updateFlashSession = (data: IFlashSessionListItem) => {
  return instacne.post(`/flashSession/update/${data.id}`, data);
};

/* 
    秒杀时间段启用状态
    /flashSession/update/status/{id}
*/
interface updateFlashSessionStatusParams {
  id: number | Ref<number>;
  status: number | Ref<number>;
}
const updateFlashSessionStatus = (data: updateFlashSessionStatusParams) => {
  return instacne.post(
    `/flashSession/update/status/${data.id}?status=${data.status}`
  );
};

/* 
    添加时间场次
    /flashSession/create
*/
const createFlashSession = (
  data: IFlashSessionListItem
): Promise<IFlashSessionListItem> => {
  return instacne.post("/flashSession/create", data);
};

/* 
    删除时间场次
    /flashSession/delete/{id}
*/
const deleteSession = (data: number) => {
  return instacne.post(`/flashSession/delete/${data}`);
};

/* 
    添加活动
    /flash/create
*/
const createFlashActivity = (data: IFlashListItem): Promise<IFlashListItem> => {
  return instacne.post("/flash/create", data);
};

/* 
    编辑活动
    /flash/update/{id}
*/
const updateActivity = (data: IFlashListItem) => {
  return instacne.post(`flash/update/${data.id}`, data);
};

/* 
    设置商品接口
    /flashSession/selectList
*/
interface IFlashSelectListQuery {
  flashPromotionId: number | Ref<string> | number;
}

interface IFlashSelectList {
  id: number;
  name: string;
  startTime: string;
  endTime: string;
  status: number;
  createTime: null;
  productCount: number;
}

const getFlashSelectList = (
  data: IFlashSelectListQuery
): Promise<IFlashSelectList> => {
  return instacne.get(`/flashSession/selectList`, { params: data });
};

/* 
    秒杀商品列表
    /flashProductRelation/list
*/
// 秒杀商品列表接口
interface flashProductRelationListParams {
  flashPromotionId: number | Ref<number>;
  flashPromotionSessionId: number | Ref<number>;
  pageNum?: number | Ref<number>;
  pageSize?: number | Ref<number>;
}
interface flashProductRelationListItem {
  flashPromotionCount: number;
  flashPromotionId: number;
  flashPromotionLimit: number;
  flashPromotionPrice: number;
  flashPromotionSessionId: number;
  id: number;
  product: {};
  productId: number;
  sort: number;
}
interface flashProductRelationListRes {
  pageNum: number;
  pageSize: number;
  totalPage: number;
  total: number;
  list: flashProductRelationListItem[];
}
const getflashProductRelationList = (
  data?: flashProductRelationListParams
): Promise<flashProductRelationListRes> => {
  return instacne.get("/flashProductRelation/list", { params: data });
};

/* 
    删除商品关联
    /flashProductRelation/delete/{id}
*/
const deleteFlashProductRelation = (data: number | string) => {
  return instacne.post(`/flashProductRelation/delete/${data}`);
};

/* 
    秒杀商品列表弹出框数据
    /product/list
*/
interface IProductListParams {
  brandId?: string | Ref<string> | number;
  keyword?: string | Ref<string> | number;
  pageNum?: string | Ref<string> | number;
  pageSize?: string | Ref<string> | number;
  productCategoryId?: string | Ref<string> | number;
  productSn?: string | Ref<string> | number;
  publishStatus?: string | Ref<string> | number;
  verifyStatus?: string | Ref<string> | number;
}
interface IProductListItem {
  albumPics: string;
  brandId: number;
  brandName: string;
  deleteStatus: number;
  description: string;
  detailDesc: string;
  detailHtml: string;
  detailMobileHtml: string;
  detailTitle: string;
  feightTemplateId: number;
  giftGrowth: number;
  giftPoint: number;
  id: number;
  keywords: string;
  lowStock: number;
  name: string;
  newStatus: number;
  note: string;
  originalPrice: number;
  pic: string;
  previewStatus: number;
  price: number;
  productAttributeCategoryId: number;
  productCategoryId: number;
  productCategoryName: string;
  productSn: string;
  promotionEndTime: string;
  promotionPerLimit: number;
  promotionPrice: number;
  promotionStartTime: string;
  promotionType: number;
  publishStatus: number;
  recommandStatus: number;
  sale: number;
  serviceIds: string;
  sort: number;
  stock: number;
  subTitle: string;
  unit: string;
  usePointLimit: number;
  verifyStatus: number;
  weight: number;
}
interface IProductListRefs {
  pageNum: number;
  pageSize: number;
  total: number;
  totalPage: number;
  list: IProductListItem[];
}
const productList = (data?: IProductListParams): Promise<IProductListRefs> => {
  return instacne.get("/product/list", {
    params: data,
  });
};

/* 
    秒杀活动列表修改上下线状态
   /flash/update/status/{id}
*/
interface IUpdateStatus {
  id: number | Ref<number>;
  status: number | Ref<number>;
}
const updateStatus = (data: IUpdateStatus) => {
  return instacne.post(`/flash/update/status/${data.id}?status=${data.status}`);
};

/* 
    删除活动
    /flash/delete/195
*/
const deleteFlash = (data: number) => {
  return instacne.post(`/flash/delete/${data}`);
};

//品牌列表的
const getBrand = (
  data?: IFlashListParams
): Promise<flashProductRelationListRes> => {
  return instacne.get("/home/brand/list", {
    params: data,
  });
};
//新品列表的
const getNewProducts = (
  data?: IFlashListParams
): Promise<flashProductRelationListRes> => {
  return instacne.get("/home/newProduct/list", {
    params: data,
  });
};
//人气列表的
const getPopularity = (
  data?: IFlashListParams
): Promise<flashProductRelationListRes> => {
  return instacne.get("/home/recommendProduct/list", {
    params: data,
  });
};
//专题列表的
const getSpecial = (
  data?: IFlashListParams
): Promise<flashProductRelationListRes> => {
  return instacne.get("/home/recommendSubject/list", {
    params: data,
  });
};

//广告列表的
const getAdver = (
  data?: IFlashListParams
): Promise<flashProductRelationListRes> => {
  return instacne.get("/home/advertise/list", {
    params: data,
  });
};

/* 
    优惠券列表
    /coupon/list
*/
interface ICouponListParams {
  name?: string | Ref<string>;
  pageNum?: number | Ref<number> | string;
  pageSize?: number | Ref<number> | string;
  type?: string | Ref<string> | number;
}
interface ICouponListItem {
  amount: number;
  code: string;
  count: number;
  enableTime: string;
  endTime: string;
  id: number;
  memberLevel: number;
  minPoint: number;
  name: string;
  note: string;
  perLimit: number;
  platform: number;
  publishCount: number;
  receiveCount: number;
  startTime: string;
  type: number | string;
  useCount: number;
  useType: number;

}
interface ICouponListRefs {
  pageNum: number;
  pageSize: number;
  total: number;
  totalPage: number;
  list: ICouponListItem[];
}
const getCouponList = (data?: ICouponListParams): Promise<ICouponListRefs> => {
  return instacne.get("/coupon/list", { params: data });
};

/* 
    添加优惠券
    /coupon/create
*/
interface ICreateCoupon {
  amount?: number | null;
  enableTime?: string;
  endTime?: string;
  minPoint?: number | null;
  name?: string;
  note?: string;
  perLimit?: number | null;
  platform?: number | null;
  productCategoryRelationList?: IProductCategoryRelationList[];
  productRelationList?: IProductRelationList[];
  publishCount?: number | null;
  startTime?: string;
  type?: number | null;

  useType?: number | null;
  code?: string;
  count?: number;
  id?: number;
  memberLevel?: number;
  receiveCount?: number;
  useCount?: number;
}
interface IProductCategoryRelationList {
  couponId: number;
  id: number;
  parentCategoryName: string;
  productCategoryId: number;
  productCategoryName: string;
}
interface IProductRelationList {
  couponId: number;
  id: number;
  productId: number;
  productName: string;
  productSn: string;
}
const createCouponItem = (data: ICreateCoupon) => {
  return instacne.post("/coupon/create", data);
};

/* 
    获取单个优惠券的详细信息
    /coupon/{id}
*/
const getCoupon = (data: number | string | null) => {
  return instacne.get(`/coupon/${data}`);
};

/* 
    编辑优惠券
    /coupon/update/{id}
*/
const upDateCoupon = (data: number | string | null, form: ICreateCoupon) => {
  return instacne.post(`/coupon/update/${data}`, form);
};

/* 
    删除优惠券
    /coupon/delete/{id}
*/
const deleteCoupon = (data: number) => {
  return instacne.post(`/coupon/delete/${data}`);
};

/* 
  修改推荐品牌排序
  /home/brand/update/sort/{id}
*/

const updateSort = (data: any) => {
  return instacne.post(`/home/brand/update/sort/${data.id}?sort=${data.sort}&id=${data.id}`)
}

/* 
  批量删除推荐品牌
  /home/brand/delete
*/
const deleteBrand = (data: any) => {
  return instacne.post(`/home/brand/delete/?ids=${data}`)
}

/* 
  选择品牌列表
  /brand/list
*/
const getBrandList = (data: any): Promise<any> => {
  return instacne.get('/brand/list', {
    params: data
  })
}

/* 
  批量修改推荐品牌状态
  /home/brand/update/recommendStatus
*/
const postUpdateRecommendStatus = (data: any) => {
  return instacne.post(`/home/brand/update/recommendStatus/?ids=${data.ids}&recommendStatus=${data.recommendStatus}`)
}

export {
  getFlashList,
  getFlashSessionList,
  createFlashActivity,
  updateActivity,
  getFlashSelectList,
  updateStatus,
  deleteFlash,
  updateFlashSession,
  createFlashSession,
  deleteSession,
  deleteFlashProductRelation,
  getflashProductRelationList,
  updateFlashSessionStatus,
  getCouponList,
  deleteCoupon,
  createCouponItem,
  upDateCoupon,
  getCoupon,
  productList,
  getAdver,
  getSpecial,
  getPopularity,
  getNewProducts,
  getBrand,
  updateSort,
  deleteBrand,
  getBrandList,
  postUpdateRecommendStatus
};
export type {
  IFlashListParams,
  IFlashListItem,
  IFlashListRes,
  IFlashSelectListQuery,
  IFlashSessionListItem,
  IFlashSelectList,
  IUpdateStatus,
  flashProductRelationListRes,
  flashProductRelationListParams,
  ICouponListItem,
  ICouponListRefs,
  ICreateCoupon,
  IProductListParams,
};
